Shell scripts are often used in various operating systems to automate the execution of functions that are performed by an operating system shell. The shell is the operating system's command interpreter and the set of commands used to communicate with the system. A shell script is a text file that contains a sequence of commands for an operating system, for example a UNIX-based operating system. The term shell script is used because it combines into a single file a sequence of commands that would otherwise have to be entered into the system from a keyboard one at a time.
In general, a shell script is typically created for command sequences for which a user has a repeated need. A sequence of commands that is associated with a shell script can be initiated by simply entering the name of the shell script in a command line. For example, in UNIX, the shell acts as an interpreter that executes each command line within a shell script by line.
A technique for identifying errors in a shell script is through the use of the sh -n command. If there are syntactic errors in a shell script, checking syntactic correctness of a shell script may be performed by using the shell command sh-n.
However, drawback with using the “sh-n” command is that even though it reports syntactic errors, a syntactically correct script may still incur errors when executed. For example, a shell script that is syntactically correct may still have semantic problems. This can cause execution failures when the shell scripts are executed. The ramifications of such errors can be unpredictable, including abnormal hang/termination of the shell script.
Another technique for errors in shell scripts is through manual checking of all the commands in the file to determine whether there could be potential sources of bugs. This method of manual checking including code walk through/inspections and unit testing is the only means available for detecting such problems before executing a script. In this method all the commands in the file are checked manually to see whether there could be potential sources of bugs. A drawback to this method of error detection is that it requires manual error checking by a human. The potential for error is significant using this method as all the problems may not be identified with manual checking of shell scripts.
Yet another error detection technique for shell scripts is to run the shell script to determine if there are errors. A drawback with running a script to determine whether there are errors is that running a shell script can often change environment variables during execution. Environment variables are special variables which maintain data regarding information such as the users' login directory, terminal type, or mailbox location. For example, when a program is executed in a UNIX environment, UNIX passes the values of all the environment variables to the shell. Therefore, a drawback to this method of error checking is that running the shell scripts often changes the environment variables, and executing the script has an immediate and sometimes deleterious effect on the environment.
Based on the foregoing, it is highly desirable to have a shell script verification mechanism that can perform increased error checking on shell scripts over traditional techniques. Furthermore, it is highly desirable to provide a shell script verification mechanism that can perform advanced error checking without actually executing the script.